﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using Npgsql;

namespace IonosphereViewer
{
    public partial class _Default : System.Web.UI.Page
    {
        // PostgeSQL-style connection string
        static string constring = String.Format("Server={0};Port={1};" +
               "User Id={2};Password={3};Database={4};",
                  "192.168.0.171", "5432", "tanya", "1234", "card_crm");
               //ConfigurationSettings.AppSettings["host"],
               //ConfigurationSettings.AppSettings["port"],
               //ConfigurationSettings.AppSettings["user"],
               //ConfigurationSettings.AppSettings["ps"],
               //ConfigurationSettings.AppSettings["db"]);

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Error += new EventHandler(_Default_Error);
            NpgsqlConnection conn = new NpgsqlConnection(constring);
            conn.Open();
            try
            {
                NpgsqlCommand dccard = new NpgsqlCommand("SELECT "+ 
                                                          "cardinfo.group_no,"+ 
                                                          "cardinfo.discount,"+  
                                                          "transinfo.kind,"+  
                                                          "transinfo.summa,"+  
                                                          "transinfo.rkdate,"+  
                                                          "cardinfo.card_no,"+  
                                                          "cardinfo.holder "+ 
                                                        "FROM "+  
                                                          "public.cardinfo,"+  
                                                          "public.transinfo "+ 
                                                        "WHERE "+  
                                                          "transinfo.card_no = cardinfo.card_no AND "+ 
                                                          "cardinfo.card_no = 40120 "+ 
                                                        "ORDER BY "+ 
                                                          "cardinfo.card_no ASC,"+  
                                                          "cardinfo.holder ASC,"+  
                                                          "cardinfo.discount ASC,"+  
                                                          "transinfo.rkdate ASC,"+
                                                          "transinfo.kind ASC," +  
                                                          "transinfo.summa ASC;", conn);
                DataGridInfo.DataSource = dccard.ExecuteReader();
                DataGridInfo.DataBind();
            }
            finally
            {
                conn.Close();
            }
        }

        protected void ButtonStat_Click(object sender, EventArgs e)
        {
            string theInfo = "";
            theInfo += String.Format("<Li> Is the client AOL? {0}", Request.Browser.AOL);
            theInfo += String.Format("<Li> Does the client support ActiveX? {0}", Request.Browser.ActiveXControls);
            theInfo += String.Format("<Li> Is the client a Beta? {0}", Request.Browser.Beta);
            theInfo += String.Format("<Li> Does the client support Java Applets? {0}", Request.Browser.JavaApplets);
            theInfo += String.Format("<Li> Does the client support Cookies? {0}", Request.Browser.Cookies);
            theInfo += String.Format("<Li> Does the client support VBScript? {0}", Request.Browser.VBScript);
            LabelInfo.Text = theInfo;
            Response.Write("Была получена информация о браузере клиента.");
        }

        void _Default_Error(object sender, EventArgs e)
        {
            //Response.Clear();
            Response.Write("Page Error!<br>");
            Response.Write(string.Format("Error: <b>{0}</b>", Server.GetLastError().Message));
            Server.ClearError();
        }
    }
}
